home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / misc / math / libalgo.lha / algomath / src / goldbach.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-30  |  641 b   |  42 lines

  1. /*  Goldbach's Conjecture  */
  2.  
  3. #include "defs.h"
  4.  
  5. int am_goldbach(int a, int *d1, int *d2)
  6. {
  7. int x;
  8. int e;
  9.  
  10. if(a<0){
  11.     a = -a;
  12.     if( a&1 || a<4 )
  13.         return 0;
  14.  
  15.     for(x=0;x<4792;x++)
  16.      {
  17.         e=a-_am_primearray_init[x];
  18.           if(am_isprime(e))
  19.              {
  20.               *d1=-_am_primearray_init[x];
  21.               *d2=-e;
  22.               return 1;
  23.              }
  24.          }
  25.     }
  26. else{
  27.     if( a&1 || a<4 )
  28.         return 0;
  29.  
  30.     for(x=0;x<4792;x++)
  31.      {
  32.         e=a-_am_primearray_init[x];
  33.           if(am_isprime(e))
  34.              {
  35.               *d1=_am_primearray_init[x];
  36.               *d2=e;
  37.               return 1;
  38.              }
  39.          }
  40.     }
  41. return 0;
  42. }